<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        "use strict"
        var user={
            _age:0,
            get age(){  //读
                return this._age;
            },
            set age(value){  //写
                //如果是数字且在0-130之间
                if(!isNaN(value)&&value>=0&&value<=130){
                    this._age=value;
                }else{
                    throw "年龄必须是0-130之间的数字";
                }
            }
        };
        user.age=100;
        console.log(user.age);
        user.age="five";  //异常
        console.log(user.age);
    </script>
</body>
</html>